# -*- coding: utf-8 -*-

# Created on 13/08/2010

# Copyright (C) 2010  Sergio Rodrigo

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.

# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.

# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


from core.Actor import Actor
from core.Action import Action
import math

PONGBALL_REBOUND_STICK = Action(None, "Rebound Stick", None, 1.0)
PONGBALL_REBOUND_WALL = Action(None, "Rebound Wall", None, 1.0)
PONGBALL_MOVE = Action(None, "Move", None, 1.0)

#DIR_RIGHT = 0
#DIR_LEFT = 1

class PongBall(Actor):
    """ Pong-ball actor. It's not controlled by players.
    
    * Methods:
    __init__(self, x=0, y=0, xSpeed=0.0, ySpeed=0.0, angle=0.0, \
                actorGraphic=None) -- Extends Actor's method
    _updateLogic(self) -- Overrides Actor's method
    executeAction(self, action) -- Overrides Actor's method
    
    Extends Actor.
    
    """
    
    def __init__(self, x=0, y=0, xSpeed=0.0, ySpeed=0.0, angle=0.0, \
                actorGraphic=None):
        """ Constructor.
        
            Arguments:
        x -- Integer x position (default 0)
        y -- Integer y position (default 0)
        xSpeed -- Float x speed (default 0.0)
        ySpeed -- Float y speed (default 0.0)
        angle -- Float angle used to change the movement direction (default 0.0)
        actorGraphic -- ActorGraphic object (default None)
        
        """
        Actor.__init__(self, x, y, actorGraphic)
        self.xSpeed = xSpeed
        self.ySpeed = ySpeed
        self.angle = angle
        #self.direction = DIR_RIGHT
        #if (angle >= 90 and angle <= 270):
        #    self.direction = DIR_LEFT

    def _updateLogic(self):
        self.x = self.x + math.cos(self.angle * math.pi/180) * self.xSpeed
        self.y = self.y + math.sin(self.angle * math.pi/180) * self.ySpeed

    def executeAction(self, action):
        if action.name == "Rebound Wall":
            if self.angle >= 0 and self.angle < 90:
                self.angle += 270
            elif self.angle >= 90 and self.angle < 180:
                self.angle += 90
            elif self.angle >= 180 and self.angle < 270:
                self.angle -= 90
            elif self.angle >= 270 and self.angle < 360:
                self.angle -= 270
        if action.name == "Rebound Stick":
            if self.angle >= 0 and self.angle < 90:
                self.angle += 90
            elif self.angle >= 90 and self.angle < 180:
                self.angle -= 90
            elif self.angle >= 180 and self.angle < 270:
                self.angle += 90
            elif self.angle >= 270 and self.angle < 360:
                self.angle -= 90
        if action.name == "Move":
            self._updateLogic()
            self.actorGraphic.update()
        
# eof
